import Vue from 'vue';
import VueRouter from 'vue-router';
// import Login from '../components/Login.vue';
// import Home from '../views/Home.vue';
// import Welcome from '../components/Welcome.vue';
// import User from '../components/user/User.vue';
// import Rights from '../components/permission/Rights.vue';
// import Roles from '../components/permission/Roles.vue';
// import Categories from '../components/goods/Categories.vue';
// import Params from '../components/goods/Params.vue';
// import GoodList from '../components/goods/List.vue';
// import GoodAdd from '../components/goods/Add.vue';
// import Order from '../components/order/Order.vue';
// import Report from '../components/report/Report.vue';
const Login = () => import(/* webpackChunkName:"login_home_welcome" */ '../components/Login.vue')
// import Login from './components/Login.vue'
const Home = () => import(/* webpackChunkName:"login_home_welcome" */ '../views/Home.vue')
// import Home from './components/Home.vue'
const Welcome = () => import(/* webpackChunkName:"login_home_welcome" */ '../components/Welcome.vue')
// import Welcome from './components/Welcome.vue'
const User = () => import(/* webpackChunkName:"user" */ '../components/user/User.vue')
// import Users from './components/user/Users.vue'
const Rights = () => import(/* webpackChunkName:"power" */ '../components/permission/Rights.vue')
// import Rights from './components/permission/Rights.vue'
const Roles = () => import(/* webpackChunkName:"power" */ '../components/permission/Roles.vue')
// import Roles from './components/permission/Roles.vue'
const Categories = () => import(/* webpackChunkName:"goods" */ '../components/goods/Categories.vue')
// import Categories from './components/goods/Categories.vue'
const Params = () => import(/* webpackChunkName:"goods" */ '../components/goods/Params.vue')
// import Params from './components/goods/Params.vue'
const GoodList = () => import(/* webpackChunkName:"goods" */ '../components/goods/List.vue')
// import GoodList from './components/goods/List.vue'
const GoodAdd = () => import(/* webpackChunkName:"goods" */ '../components/goods/Add.vue')
// import GoodAdd from './components/goods/Add.vue'
const Order = () => import(/* webpackChunkName:"order" */ '../components/order/Order.vue')
// import Order from './components/order/Order.vue'
const Report = () => import(/* webpackChunkName:"report" */ '../components/report/Report.vue')
// import Report from './components/report/Report.vue'

Vue.use(VueRouter);

const router = new VueRouter({
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/login',
      component: Login
    },
    {
      path: '/home',
      component: Home,
      redirect: '/welcome',
      children: [
        {
          path: '/welcome',
          component: Welcome
        },
        {
          path: '/users',
          component: User
        }, {
          path: '/rights',
          component: Rights
        }, {
          path: '/roles',
          component: Roles
        }, {
          path: '/categories',
          component: Categories
        }, {
          path: '/params',
          component: Params
        }, {
          path: '/goods',
          component: GoodList
        }, {
          path: '/goods/add',
          component: GoodAdd
        }, {
          path: '/orders',
          component: Order
        }, {
          path: '/reports',
          component: Report
        }
      ]
    }
  ]
});

router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    return next();
  }

  const tokenString = window.sessionStorage.getItem('token');

  if (!tokenString) {
    return next('/login');
  }

  next();
});

export default router;
